#include <iostream>
#include<vector>
using namespace std;

//反转字符串
class Solution
{
public:
    static void reverseString(vector<char>& s)
    {
        int left = 0;
        size_t right = s.size() - 1;
        while(left < right)
        {
            swap(s[left++], s[right--]);
        }
        for(auto e : s)
        {
            cout << e << endl;
        }
    }
};

//第一个唯一字符法一
// class Solution
// {
// public:
//     int firstUniqChar(string s)
//     {
//         for(int i = 0; i<s.size(); i++)
//         {
//             if(s.find(s[i]) == s.rfind(s[i]))
//             {
//                 return i;
//             }
//         }
//         return -1;
//     }
// };
//法二
class Solution
{
public:
    int firstUniqChar(string s)
    {
        vector<int> count(26,0);
        for(auto e : s)
        {
            count[e-'a']++;
        }
        for(size_t i = 0; i<s.size(); i++)
        {
            if(count[s[i] - 'a'] == 1)
            {
                return i;
            }
        }
        return -1;
    }
};

//最后一个单词的长度
class Solution
{
public:
    int lengthOfLastWord(string s)
    {
        size_t n = s.size() - 1;
        int i = n;
        int count = 0;
        while(s[i] == ' ' && i>=0)
        {
            i--;
        }
        while(i>=0 && s[i]!=' ')
        {
            count++;
            i--;
        }
        return count;

    }
};

//回文
class Solution
{
public:
    bool isPalindrome(string s)
    {
        string rs;
        for(auto e : s)
        {
            if(isalnum(e))
            {
                rs += tolower(e);
            }
        }

        int left = 0;
        int right = rs.size()-1;
        while(left < right)
        {
            if(rs[left] != rs[right])
            {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
};